package com.cqd.rp_goods.web;


import com.cqd.rp_goods.dto.ResultEntity;
import com.cqd.rp_goods.dto.RpDto;
import com.cqd.rp_goods.entity.DbRp;
import com.cqd.rp_goods.service.IDbRpService;
import com.fasterxml.jackson.databind.util.BeanUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mht
 * @since 2020-03-16
 */
@RestController
@CrossOrigin
@RequestMapping("/dbRp")
public class DbRpController {

    @Autowired
    IDbRpService rpService;

    @RequestMapping("/selectRpList")
    public ResultEntity selectRpList(RpDto rpDto){
        PageHelper.startPage(rpDto.getPageNum(),rpDto.getPageSize());
        List<DbRp> dbRps = rpService.selectRpList(rpDto);
        PageInfo<DbRp> info = new PageInfo<>(dbRps);
        return ResultEntity.ok(info);
    }

    @RequestMapping("selectGoodsList")
    public ResultEntity selectGoodsList(RpDto rpDto){
        PageHelper.startPage(rpDto.getPageNum(),rpDto.getPageSize());
        List<DbRp> dbRps = rpService.selectGoodsList(rpDto);
        PageInfo<DbRp> info = new PageInfo<>(dbRps);
        return ResultEntity.ok(info);
    }

//    @RequestMapping("selectById")
//    public ResultEntity selectById(@Param("id") Integer id){
//        List<DbRp> dbRps = rpService.selectById(id);
//        for (int i = 0; i <dbRps.size() ; i++) {
//            DbRp dbRp = dbRps.get(i);
//            boolean insert = rpService.insert(dbRp);
//        }
//        return ResultEntity.ok(dbRp);
//    }

    @RequestMapping("selectById")
    public ResultEntity selectById(@Param("id") Integer id) {
        DbRp dbRp = new DbRp();
        List<DbRp> dbRps = rpService.selectById(id);
        for (int i = 0; i <dbRps.size() ; i++) {
            DbRp dbRp1 = dbRps.get(i);
            System.out.println(dbRp1);
            boolean insert = rpService.insert(dbRp1);
            System.err.println(insert);
        }
        return ResultEntity.ok();
    }


    @RequestMapping("delById")
    public ResultEntity delById(Integer id){
        rpService.del(id);
        return ResultEntity.ok();
    }

}
